package com.thlws.redis.sentinel;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisSentinelPool;

import java.util.HashSet;
import java.util.Set;

/**
 * @author HanleyTang
 * @date 2018-12-15
 */
public class JedisSentinel {

    public static void main(String[] args) {

        //哨兵的地址信息
        Set<String> ips = new HashSet<>();
        ips.add("127.0.0.1:26379");
        ips.add("127.0.0.1:26380");
        ips.add("127.0.0.1:26381");

        //创建哨兵池

        try(JedisSentinelPool pool = new JedisSentinelPool("redisMaster",ips);
            Jedis jedis = pool.getResource()){
            jedis.auth("密码");//主从密码要一样

            //通过哨兵插入数据到 集群
            jedis.set("key001", "sentinel is cool.");

            pool.destroy();
        }



    }
}
